package com.diliuzun.delivery.common;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

@WebFilter(filterName = "EncodeFilter", urlPatterns = "/*")
public class EncodeFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        // 设置请求编码
        request.setCharacterEncoding("utf-8");
        chain.doFilter(request, response);
        // 设置响应内容的编码及浏览器解析响应内容用到的编码
        response.setContentType("text/html;charset=utf-8");
    }
}
